﻿package mortal.game.view.palyer.item
{
    import baseEngine.modifiers.*;
    import baseEngine.system.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import flash.geom.*;
    import mortal.component.gconst.*;
    import mortal.game.manager.window3d.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.scene3D.model.player.*;
    import mortal.game.scene3D.model.pools.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.signUp.sevenDayLogin.item.*;

    public class RoleHalidomCell extends GSprite
    {
        private var _effectPlayer:EffectPlayer;
        private var _pos:Point;
        private var _rect3d:Rect3DObject;
        private var _item:BaseItem;
        private var _toolP:HideAreaSp;
        private var _nameB:GBitmap;
        private var _index:int = -1;

        public function RoleHalidomCell()
        {
            return;
        }// end function

        public function set pos(param1:Point) : void
        {
            this._pos = param1;
            this.updatePos();
            return;
        }// end function

        public function set rect3d(param1:Rect3DObject) : void
        {
            this._rect3d = param1;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._item = UIFactory.getUICompoment(BaseItem, 16, 18, this);
            this._item.setItemStyle(ItemStyleConst.Small, ImagesConst.PackItemBg, 2, 2);
            this._item.doubleClickEnabled = true;
            this._item.isDragAble = false;
            this._item.alpha = 0.01;
            this._toolP = UIFactory.getUICompoment(HideAreaSp, 21, 0, this);
            this._toolP.drawRec(ItemStyleConst.Small, ItemStyleConst.Small, 0.01);
            this._toolP.doubleClickEnabled = true;
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this.visible = false;
            this._index = -1;
            if (this._item)
            {
                this._item.doubleClickEnabled = false;
            }
            this._item = null;
            if (this._toolP)
            {
                this._toolP.doubleClickEnabled = false;
            }
            this._toolP = null;
            if (this._nameB)
            {
                this._nameB.dispose(param1);
                this._nameB = null;
            }
            if (this._effectPlayer)
            {
                this._effectPlayer.coloredScreen = false;
                this._effectPlayer.dispose();
                this._rect3d.disposeObj3d(this._effectPlayer);
                this._effectPlayer = null;
            }
            return;
        }// end function

        private function add3DModel(param1:int) : void
        {
            var _loc_2:* = HalidomConfig.instance.getTypeItem((param1 + 1)).effect;
            if (this._effectPlayer)
            {
                this._effectPlayer.dispose();
                this._rect3d.disposeObj3d(this._effectPlayer);
            }
            this._effectPlayer = EffectPlayerPool.instance.getEffectPlayer(_loc_2, null, this._rect3d.renderList, false);
            this._effectPlayer.hangBoneName = BoneConst.MountHangModelBone;
            this._effectPlayer.play(PlayMode.ANIMATION_LOOP_MODE);
            var _loc_3:Number = 0.7;
            this._effectPlayer.scaleZ = 0.7;
            var _loc_3:* = _loc_3;
            this._effectPlayer.scaleY = _loc_3;
            this._effectPlayer.scaleX = _loc_3;
            this._effectPlayer.coloredScreen = true;
            this._rect3d.addObject3d(this._effectPlayer, this._pos.x + 35, this._pos.y + 36);
            return;
        }// end function

        public function updateName(param1:int) : void
        {
            this._index = param1;
            if (this._nameB)
            {
                this._nameB.dispose();
            }
            LoaderHelp.addResCallBack(ResFileConst.halidom2, this.onLoad);
            return;
        }// end function

        private function onLoad() : void
        {
            if (isDisposed || this._index == -1)
            {
                return;
            }
            this._nameB = UIFactory.bitmap(ImagesConst["HalidomRT" + this._index], 0, 0, this);
            if (this._pos)
            {
                this._nameB.x = this._pos.x + 13;
                this._nameB.y = this._pos.y + 37;
            }
            return;
        }// end function

        public function clearCell() : void
        {
            if (this._effectPlayer)
            {
                this._effectPlayer.dispose();
                this._rect3d.disposeObj3d(this._effectPlayer);
                this._effectPlayer = null;
            }
            this._toolP.visible = false;
            return;
        }// end function

        public function updateInfo(param1:int) : void
        {
            if (this._item.itemData)
            {
                this.add3DModel(param1);
                this._toolP.toolTipData = this._item.toolTipData;
                this._toolP.visible = true;
            }
            return;
        }// end function

        public function set colorScreen(param1:Boolean) : void
        {
            if (this._effectPlayer)
            {
                this._effectPlayer.coloredScreen = param1;
            }
            if (this._toolP)
            {
                this._toolP.doubleClickEnabled = !param1;
            }
            return;
        }// end function

        private function updatePos() : void
        {
            this._item.x = this._pos.x + 13;
            this._item.y = this._pos.y + 15;
            this._toolP.x = this._pos.x + 23;
            this._toolP.y = this._pos.y + 0;
            return;
        }// end function

        override public function set visible(param1:Boolean) : void
        {
            super.visible = param1;
            if (this._effectPlayer)
            {
                if (param1)
                {
                    this._effectPlayer.addedToScene(Global3D.scene);
                }
                else
                {
                    this._effectPlayer.removedFromScene();
                }
            }
            return;
        }// end function

        public function get item() : BaseItem
        {
            return this._item;
        }// end function

        public function get toolP() : HideAreaSp
        {
            return this._toolP;
        }// end function

    }
}
